// JavaScript Document
var currentTab = null;
var choosenTab = null;

function bindTabs() {
	// Set current tab variable when image is clicked
	$('#accordion img').each(function() {
        $(this).bind('click', function() {
			currentTab = $(this);
		});
    });
}

function bindNext() {
	$('.btn-next').bind('click', function(){ 
		 choosenTab = currentTab.nextUntil('img').next();
		 
		 if (choosenTab.length != 0) { // Next image tag found
			 choosenTab.get(0).click();
			 currentTab = choosenTab;
		 }
		 return false;
	});
}

function bindPrevious() {
	$('.btn-prev').bind('click', function(){
		choosenTab = currentTab.prevUntil('img').prev();
		
		if (choosenTab.length != 0) { // Previous image tag found
			choosenTab.get(0).click();
			currentTab = choosenTab;
		}
		
		return false;
	});
}

$(document).ready(function(e) {
	currentTab = $('#accordion').find('img.current');
    
	bindTabs();
	bindPrevious();
	bindNext();
});

